<?php
/**
* @version $Id: comment.php,v 1.0 2005/10/02 13:15:15 mic Exp $
* @package XfaQ - a frequently asked question component for Joomla! & Mambo CMS
* @copyright (C) 2005 mgfi.info
* @info info@mgfi.info http://www.mgfi.info
* @license GNU/GPL
* based in simplefaq 2.0.1 & glossary 1.4
*/

# Don't allow direct linking
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/HTML_toolbar.php' );

$id=mosGetParam( $_REQUEST, 'id','' );
$page=mosGetParam( $_REQUEST, 'page','1' );

global $my, $is_editor, $is_admin;
global $name, $email, $location, $question, $homepage, $answer;
global $date_created, $comment, $edit, $editdate;
?>

<script type="text/javascript" src="includes/js/mambojavascript.js"></script>
<script type="text/javascript">
	<!--
	function validate(){
		if (document.adminForm.comment.value==''){
		} else {
			document.adminForm.action = 'index.php';
			document.adminForm.submit();
		}
	}

	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			document.adminForm.task.value = 'cancel';
			submitform( pressbutton );
			return;
		}

		if (pressbutton == 'save') {
			validate();
			return;
		}
    }
    //-->
</script>

<?php
# Main Part of Subfunction
if( $is_editor ){ ?>
    <table align="center" width="99%" CELLPADDING="0" CELLSPACING="4" BORDER="0">
        <tr>
            <td width="90%"></td>
            <td align="right">
                <?php
                mosToolBar::startTable();
                mosToolBar::save();
                //mosToolBar::back();
                mosToolBar::cancel();
                mosToolBar::endtable(); ?>
            </td>
        </tr>
    </table>

	<?php
  	if( mosGetParam( $_REQUEST, 'opt', '' ) == 'del' ){
        $query1 = 'UPDATE #__xfaq SET comment=\'\' WHERE id=\'' . $id . '\'';
        $result=$database->setquery($query1);
        $result=$database->query();
        echo "<SCRIPT> alert('"._XFAQ_COMMENTDELETED."'); document.location.href='index.php?option=com_xfaq&task=display&page=$page&Itemid=$Itemid&catid=$catid';</SCRIPT>";
    } else {
        if( $comment ) {
            $query1 = 'UPDATE #__xfaq SET comment=\'' . $comment . '\' WHERE id=\'' . $id . '\'';
            $result=$database->setquery($query1);
            $result=$database->query();
            echo "<SCRIPT> alert('"._XFAQ_COMMENTSAVED."'); document.location.href='index.php?option=com_xfaq&task=display&page=$page&Itemid=$Itemid&catid=$catid';</SCRIPT>";
        } else {
            $query1 = 'SELECT * FROM #__xfaq WHERE id = \'' . $id . '\'';
            $result1 = $database->setquery($query1);
            $row=$database->loadobjectlist($result1);

            #Show the Original Entry
            ?>
            <table width="100%" border="0" cellspacing="1" cellpadding="4">
            	<tr>
            		<td width="30%" height="20" class="sectiontableheader"><?php echo _XFAQ_NAME; ?></td>
            		<td width="70%" height="20" class="sectiontableheader"><?php echo _XFAQ_DETAILS; ?></td>
            	</tr>
            	<tr class="sectiontableentry1">
            		<td width="30%" valign="top">
            			<strong><?php echo $row[0]->question; ?></strong>
            			<?php
            			if( $name <> '' ){ ?>
                			<br />
                			<span class="small"><?php echo _XFAQ_AUTHOR . ': ' . $row[0]->name; ?></span>
                			<?php
                		} ?>
            		</td>
            		<?php

                    $signtime = $row[0]->date_created;
                    $origtext = $row[0]->answer; ?>
                    <td width="70%" valign="top">
                    	<span class="small">
                    		<?php echo _XFAQ_SIGNEDON . ' - ' . $signtime; ?>
                    		<hr />
                    	</span>
                    	<?php echo $origtext; ?>
                    </td>
                </tr>
                <tr class="sectiontableentry1">
                	<td colspan="2" valign="top">
                		<?php
                    	if( $row[0]->location <> '' ){
                        	echo _XFAQ_FROM . '<span class="small">: ' . $row[0]->location . '</span><br />';
                        }
                    	if( $row[0]->email <> '' ){
                        	echo '<a href="mailto:' . $row[0]->email . '"><img src="components/com_xfaq/images/email.gif" alt="' . $row[0]->email . '" hspace="3" border="0" /></a>';
                        }
                    	if( $row[0]->homepage <> '' ){
                        	echo '<a href="' . $row[0]->homepage . '" target="_blank" title="' . $row[0]->homepage . '"><img src="components/com_xfaq/images/homepage.gif" alt="' . $row[0]->homepage . '" hspace="3" border="0" /></a>';
                        } ?>
                    </td>
                </tr>

            	<form name="adminForm" action="index.php" target="_top" method="post">
            	<input type="hidden" name="id" value="<?php echo $id; ?>" />
            	<input type="hidden" name="catid" value="<?php echo $catid; ?>" />
            	<input type="hidden" name="option" value="com_xfaq" />
            	<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
            	<input type="hidden" name="page" value="<?php echo $page; ?>">
            	<input type="hidden" name="task" value="comment">
            	<tr class="sectiontableentry2">
            		<td valign="top">
            			<strong><?php echo _XFAQ_ACOMMENTS; ?></strong>
            			<br /><br />\
            		</td>
            		<td valign="top">
            			<textarea cols="70" rows="8" name="comment" class="inputbox" wrap="virtual"><?php echo $row[0]->comment; ?></textarea>
            		</td>
            	</tr>
            </form>
          </table>
          <?php
        }
    }
} else { ?>
    <p>
    	<a href="<?php echo sefRelToAbs( 'index.php?option=com_xfaq&amp;page=' . $page . '&amp;Itemid=' . $Itemid ); ?>"><?php echo _XFAQ_BACK; ?></a>
    </p>
    <?php
}
?>